package vip.guzb.demo;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 任务执行器的停机回调钩子
 *
 * @author 顾志兵
 * @mail ipiger@163.com
 * @since 2024-03-26
 */
@Component
public class ExecutorShutdownHook implements DisposableBean {

    @Resource
    ThreadPoolTaskExecutor taskExecutor;

    @Override
    public void destroy() throws Exception {
        System.out.println("[ShutdownHook]: 开始停止任务执行器");
        taskExecutor.shutdown();
        System.out.println("[ShutdownHook]: 任务执行器已平滑停止");
    }

}
